home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / CheckButtonImage.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  3.7 KB  |  137 lines  |  [TEXT/CWIE]

  1. // CheckButtonImage.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9.  
  10. /** Image subclass that draws the images displayed by "check" buttons.
  11.   *
  12.   * @private
  13.   */
  14.  
  15.  
  16. public class CheckButtonImage extends Image {
  17.     boolean             drawsCheckMark;
  18.  
  19.     final static String         DRAWS_CHECK_KEY = "drawsCheckMark";
  20.  
  21.     private static Bitmap       checkBitmap;
  22.  
  23.     private Bitmap checkBitmap() {
  24.         if (checkBitmap == null) {
  25.             checkBitmap =
  26.                 Bitmap.bitmapNamed("netscape/application/CheckMark.gif");
  27.         }
  28.  
  29.         return checkBitmap;
  30.     }
  31.  
  32.     /** Constructs a CheckButtonImage without a check mark. */
  33.     public CheckButtonImage() {
  34.         super();
  35.     }
  36.  
  37.     /** Constructs a CheckButtonImage that draws or does not draw a check mark.
  38.       */
  39.     public CheckButtonImage(boolean drawsCheckMark) {
  40.         this();
  41.  
  42.         this.drawsCheckMark = drawsCheckMark;
  43.     }
  44.  
  45.     /** Sets whether the CheckButtonImage displays a check mark. */
  46.     public void setDrawsCheckMark(boolean flag) {
  47.         drawsCheckMark = flag;
  48.     }
  49.  
  50.     /** Returns <b>true</b> if the CheckButtonImage displays a check mark. */
  51.     public boolean drawsCheckMark() {
  52.         return drawsCheckMark;
  53.     }
  54.  
  55.     /** Returns the CheckButtonImage's width. */
  56.     public int width() {
  57.         return 16;
  58.     }
  59.  
  60.     /** Returns the CheckButtonImage's height. */
  61.     public int height() {
  62.         return 16;
  63.     }
  64.  
  65.     /** Draws the CheckButtonImage at the given location. */
  66.     public void drawAt(Graphics g, int x, int y) {
  67.         Rect    tmpRect;
  68.  
  69.         tmpRect = Rect.newRect(x, y, width(), height());
  70.  
  71.         BezelBorder.raisedButtonBezel().drawInRect(g, tmpRect);
  72.         g.setColor(Color.lightGray);
  73.         g.fillRect(tmpRect.x + 2, tmpRect.y + 2, tmpRect.width - 4,
  74.                    tmpRect.height - 4);
  75.         //Button.drawButton(g, tmpRect, false);
  76.  
  77.         if (drawsCheckMark) {
  78.             checkBitmap().drawCentered(g, tmpRect);
  79.         }
  80.  
  81.         Rect.returnRect(tmpRect);
  82.     }
  83.  
  84.     /** Draws the CheckButtonImage scaled to fit the supplied rectangle.
  85.       */
  86.     public void drawScaled(Graphics g, int x, int y, int width, int height) {
  87.         Rect    tmpRect;
  88.  
  89.         tmpRect = Rect.newRect(x, y, width, height);
  90.  
  91.         BezelBorder.raisedButtonBezel().drawInRect(g, tmpRect);
  92.         g.setColor(Color.lightGray);
  93.         g.fillRect(tmpRect.x + 2, tmpRect.y + 2, tmpRect.width - 4,
  94.                    tmpRect.height - 4);
  95.         //Button.drawButton(g, tmpRect, false);
  96.  
  97.         if (drawsCheckMark) {
  98.             checkBitmap().drawCentered(g, x, y, width, height);
  99.         }
  100.  
  101.         Rect.returnRect(tmpRect);
  102.     }
  103.  
  104.     /** Describes the CheckButtonImage class' coding information.
  105.       * @see Codable#describeClassInfo
  106.       */
  107.     public void describeClassInfo(ClassInfo info) {
  108.         info.addClass("netscape.application.CheckButtonImage", 1);
  109.         info.addField(DRAWS_CHECK_KEY, BOOLEAN_TYPE);
  110.     }
  111.  
  112.     /** Encodes the CheckButtonImage.
  113.       * @see Codable#encode
  114.       */
  115.     public void encode(Encoder encoder) throws CodingException {
  116.         super.encode(encoder);
  117.  
  118.         encoder.encodeBoolean(DRAWS_CHECK_KEY, drawsCheckMark);
  119.     }
  120.  
  121.     /** Decodes the CheckButtonImage.
  122.       * @see Codable#decode
  123.       */
  124.     public void decode(Decoder decoder) throws CodingException {
  125.         super.decode(decoder);
  126.  
  127.         drawsCheckMark = decoder.decodeBoolean(DRAWS_CHECK_KEY);
  128.     }
  129.  
  130.     /** Finishes the CheckButtonImage decoding; only calls super.
  131.       * @see Codable#finishDecoding
  132.       */
  133.     public void finishDecoding() throws CodingException {
  134.         super.finishDecoding();
  135.     }
  136. }
  137.